package com.example.demo.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 获取配置文件使用Environment-spring运行时环境对象
 * @author jiaqi.liu
 *
 */
@RestController
@PropertySource(value="classpath:conf.properties")
public class PropsControllerDemo3 {
	
	@Autowired
	private Environment env;
	
	@GetMapping("/getPropsMethodThree")
	public Map<String,String> getPropsMethodThree(){
		
		Map<String,String> map=new HashMap<String,String>();
		map.put("name", env.getProperty("person.name"));
		map.put("age", env.getProperty("person.age"));
		return map;
	}
	
}
